package main;


import base.BaseWindow;

import main.inquiry.*;
import main.record.ExamTable;
import main.record.MakeupTable;
import main.record.RenovateTable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class HomeWindow extends BaseWindow {

    private JMenuBar mb = new JMenuBar();    //菜单栏
    private JMenu s_rg = new JMenu("成绩录入");
    private JMenu print = new JMenu("信息查询");
    private JMenu exit = new JMenu("退出系统");

    private JMenuItem exam_rg = new JMenuItem("考试成绩录入");    //菜单项
    private JMenuItem makeup_rg = new JMenuItem("补考成绩录入");
    private JMenuItem renovate_rg = new JMenuItem("重修成绩录入");

    private JMenuItem final_score = new JMenuItem("总评成绩单");
    private JMenuItem makeup_notice = new JMenuItem("补考通知单");
    private JMenuItem makeup_score = new JMenuItem("补考成绩单");
    private JMenuItem renovate_notice = new JMenuItem("重修通知单");
    private JMenuItem renovate_score = new JMenuItem("重修成绩单");
    private JMenuItem excellent_student = new JMenuItem("优秀学生名单");
    private JMenuItem xx_table = new JMenuItem("XX_Table");

    private JMenuItem exit_system = new JMenuItem("退出系统");
    private JLabel label = new JLabel();

    @Override
    protected JFrame setRootView() {
        JFrame fm = new JFrame("学生成绩管理系统");
        fm.setBounds(450, 180, 500, 350);
        fm.setSize(500, 350);
        fm.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                if ((JFrame) e.getSource() == fm)        //点击fm的x按钮触发的事件
                    System.exit(0);
            }
        });
        return fm;
    }

    @Override
    protected void initView(JFrame root) {
        exit.add(exit_system);
        exit_system.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                exitSystem();
            }
        });

        s_rg.add(exam_rg);    //成绩登记菜单添加菜单项
        s_rg.add(makeup_rg);
        s_rg.add(renovate_rg);
        exam_rg.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                examRg();
            }
        });    //菜单项添加监听器
        makeup_rg.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                makeupRg();
            }
        });
        renovate_rg.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                renovateRg();
            }
        });

        print.add(final_score);    //信息查询菜单添加菜单项
        print.add(makeup_notice);
        print.add(makeup_score);
        print.add(renovate_notice);
        print.add(renovate_score);
        print.add(excellent_student);
        print.add(xx_table);

        final_score.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                finalScore();
            }
        });    //绑定监听器
        makeup_notice.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                makeupNotice();
            }
        });
        makeup_score.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                makeupScore();
            }
        });
        renovate_notice.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                renovateNotice();
            }
        });
        renovate_score.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                renovateScore();
            }
        });
        excellent_student.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                excellentStudent();
            }
        });

        mb.add(s_rg);        //菜单栏添加菜单
        mb.add(print);
        mb.add(exit);
        root.setJMenuBar(mb);        //窗口添加菜单栏

        label.setText("总评成绩 = 平时成绩*0.3 + 考试成绩*0.7！！！");
        root.add(label, BorderLayout.NORTH);
    }

    @Override
    protected void loadData() {

    }

    private void examRg() {
        new ExamTable().start();
    }

    private void makeupRg() {
        new MakeupTable().start();
    }

    private void renovateRg() {
        new RenovateTable().start();
    }

    private void finalScore() {
        new FinalScoreCanvas().start();
    }

    private void makeupNotice() {
        new MakeupNoticeCanvas().start();
    }

    private void makeupScore() {
        new MakeupScoreCanvas().start();
    }

    private void renovateNotice() {
        new RenovateNoticeCanvas().start();
    }

    private void renovateScore() {
        new RenovateScoreCanvas().start();
    }

    private void excellentStudent() {
        new ExcellentStudentCanvas().start();
    }

    private void exitSystem() {
        System.exit(0);
    }

}
